home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Menu Fixer 1.0 Source / Menu fixer ƒ / Fix code ƒ / fix meat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-14  |  2.6 KB  |  91 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        fix meat.c
  4.  
  5. Purpose:    This module handles actually checking menu resource IDs
  6.             and internal menuIDs and alerting the user of discrepancies.
  7.  
  8.  
  9. Menu Fixer -=- synchronize menu IDs and menu resource IDs
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "fix structs.h"
  30. #include "fix meat.h"
  31. #include "msg dialogs.h"
  32.  
  33. int            gNumTotalMenus;
  34. int            gNumFixedMenus;
  35. int            gNumBadMenus;
  36.  
  37. int MenuFixer(FSSpec myFSS, int thisRefNum, Boolean resFileAlreadyOpen)
  38. {
  39.     MenuHandle        thisMenu;
  40.     ResType            thisResType;
  41.     unsigned int    thisID;
  42.     Str255            thisName;
  43.     int                i;
  44.     
  45.     gNumTotalMenus=Count1Resources('MENU');
  46.     if (gNumTotalMenus==0)
  47.         return noMenusErr;
  48.     
  49.     for (i=1; i<=gNumTotalMenus; i++)
  50.     {
  51.         thisMenu=GetIndResource('MENU', i);
  52.         if (*thisMenu==0L)
  53.             LoadResource(thisMenu);
  54.         GetResInfo(thisMenu, &thisID, &thisResType, thisName);
  55.         if (thisID!=**((unsigned int**)thisMenu))
  56.         {
  57.             BadMenu(myFSS, thisRefNum, thisMenu, thisID, thisName);
  58.             gNumBadMenus++;
  59.         }
  60.         if (!resFileAlreadyOpen)
  61.             ReleaseResource(thisMenu);
  62.     }
  63.     
  64.     return allsWell;
  65. }
  66.  
  67. void BadMenu(FSSpec myFSS, int thisRefNum, MenuHandle thisMenu, unsigned int thisID,
  68.     Str255 thisName)
  69. {
  70.     Str255            tempStr, tempStr2;
  71.     int                alertResult;
  72.     
  73.     NumToString(thisID, tempStr);
  74.     NumToString(**((unsigned int**)thisMenu), tempStr2);
  75.     ParamText(myFSS.name, thisName, tempStr, tempStr2);
  76.     PositionDialog('ALRT', badMenuAlert);
  77.     alertResult=Alert(badMenuAlert, 0L);
  78.     if (alertResult==2)    /* correct the problem */
  79.         CorrectMenu(myFSS, thisRefNum, thisMenu, thisID, thisName);
  80. }
  81.  
  82. void CorrectMenu(FSSpec myFSS, int thisRefNum, MenuHandle thisMenu, unsigned int thisID,
  83.     Str255 thisName)
  84. {
  85.     **((unsigned int**)thisMenu)=thisID;
  86.     ChangedResource(thisMenu);
  87.     WriteResource(thisMenu);
  88.     UpdateResFile(thisRefNum);
  89.     gNumFixedMenus++;
  90. }
  91.